package com.tong.embeddedvr.Mapper;

import com.tong.embeddedvr.dto.HostDTO;
import com.tong.embeddedvr.entity.HostEntity;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.Map;

@Repository
@Mapper
public interface HostMapper {

    /**
     * @Description 添加一个新主机
     * @Author gcl
     * @Date 2021/2/24 12:36
     * @param: hostDTO
     * @Return void
     */
    @Insert("INSERT INTO host(host_ip,host_username,host_password,host_is_delete) VALUES(#{hostEntity.hostIp},#{hostEntity.hostUsername},#{hostEntity.hostPassword},0)")
    public void addHost(@Param("hostEntity")HostEntity hostEntity);

    /**
     * @Description 更新信息
     * @Author gcl
     * @Date 2021/2/24 12:44
     * @param: hostDTO
     * @Return void
     */
    public void updateInformation(@Param("hostEntity")HostEntity hostEntity);

    /**
     * get all host information
     * @return HostBean[]
     */
    @Select("SELECT * FROM host WHERE host_is_delete = 0")
    public HostDTO[] getAllHost();

    @Select("SELECT * FROM host WHERE host_id = #{hostEntity.hostId} AND host_is_delete=0")
    public HostDTO getHostById(@Param("hostEntity")HostEntity hostEntity);

    /**
     * @Description 增加用户数
     * @Author gcl
     * @Date 2021/2/24 12:45
     * @param: hostDTO
     * @Return void
     */
    @Update("UPDATE host SET host_usernum = host_usernum + 1 WHERE host_id = #{hostEntity.hostId}")
    public void increaseUseNum(@Param("hostEntity")HostEntity hostEntity);

    /**
     * @Description 减少用户数
     * @Author gcl
     * @Date 2021/2/24 12:45
     * @param: id
     * @Return void
     */
    @Update("UPDATE host SET host_usernum = host_usernum - 1 WHERE host_id = #{hostEntity.hostId}")
    public void decreaseUseNum(@Param("hostEntity")HostEntity hostEntity);
}
